<%
String itemName = request.getParameter("itemName");
String itemYear = request.getParameter("itemYear");
String itemType = request.getParameter("itemType");
String startingPrice = request.getParameter("startingPrice");
String increment = request.getParameter("increment");
String reserve = request.getParameter("reserve");
String closeDate = request.getParameter("closeDate");

String username = ""+session.getValue("login");
String mysJDBCDriver = (String)session.getValue("mysJDBCDriver"); 
String mysURL = (String)session.getValue("mysURL"); 
String mysUserID = (String)session.getValue("mysUserID");
String mysPassword = (String)session.getValue("mysPassword");

java.sql.Connection conn=null;
try 
{
    Class.forName(mysJDBCDriver).newInstance();
	java.util.Properties sysprops=System.getProperties();
	sysprops.put("user",mysUserID);
	sysprops.put("password",mysPassword);
     
	//connect to the database
	conn=java.sql.DriverManager.getConnection(mysURL,sysprops);
	System.out.println("Connected successfully to database using JConnect");

	java.sql.Statement stmt1=conn.createStatement();
	java.sql.Statement stmt2=conn.createStatement();
	java.sql.Statement stmt3=conn.createStatement();
	java.sql.Statement stmt4=conn.createStatement();
	java.sql.Statement stmt5=conn.createStatement();
	
	java.util.Date dt = new java.util.Date();
	java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	String currentTime = sdf.format(dt);
	
	java.sql.ResultSet itemIdResult = stmt1.executeQuery("select max(Item.ItemId) from Item");
	java.sql.ResultSet auctionIdResult = stmt2.executeQuery("select max(Auction.AuctionId) from Auction");
	if (itemIdResult.next() && auctionIdResult.next())
	{
		int itemId = itemIdResult.getInt(1) + 1;
		int auctionId = auctionIdResult.getInt(1) + 1;
		stmt3.executeUpdate("insert into Item values('"+itemId+"','"+itemYear+"','"+ itemName + "', '"+itemType+"')");
		stmt4.executeUpdate("insert into Auction values('"+auctionId+"','"+currentTime+"','"+ closeDate + "', '"+startingPrice+
				"','"+reserve+"','"+increment+"','"+"5"+"')");
		stmt5.executeUpdate("insert into Selling values('"+username+"','"+auctionId+"','"+itemId+"')");
		response.sendRedirect("AuctionInfo.jsp?auctionId=" + auctionId);	
	}

} catch(Exception e)
{
	e.printStackTrace();
	out.print(e.toString());
}
finally{

	try{conn.close();}catch(Exception ee){};
}
%>